<!DOCTYPE html>
<html>
  
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="utf-8">
  <meta name="author" content="wu24">
  
  
  <title>位运算总结 | wu24</title>

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

  
    <meta name="keywords" content="c++,c++,">
  

  
  <meta name="description" content="wu24的小站">

  

  
    <script src="//cdn.jsdelivr.net/npm/leancloud-storage@3.11.1/dist/av-min.js" async></script>
  

  
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" async></script>
  

  
    <script src="//unpkg.com/valine/dist/Valine.min.js" async></script>
  

  

  <script>
  // theme-ad's config script
  // it can be used in every script
  
  window.AD_CONFIG = {
    leancloud: {"appid":"sw527FocaHIFJVk21ntEXcaI-gzGzoHsz","appkey":"fij0WHTBbI4fnbhpoJBjLQtO","comment":true,"count":true},
    welcome: {"enable":false,"interval":30},
    start_time: "2019-06-14",
    passwords: ["efe07af7441da2b69c4a41e42e73be4db47f66010a56900788a458354a7373ec", ],
    is_post: true,
    lock: false,
    author: "wu24",
    share: {"twitter":false,"facebook":false,"weibo":false,"qq":false,"wechat":false},
    mathjax: true,
    page_type: "",
    root: "/"
  };
</script>

  <script src="/vendor/sha256.min.js"></script>
<script src="/js/auth.js"></script>
<script src="/js/index.js"></script>
<script src="/vendor/qrcode.min.js"></script>

  
    <link rel="icon" href="/images/favicon.ico">
    <link rel="apple-touch-icon" href="/images/touch-icon.png">
  

  <link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

  <link rel="stylesheet" href="/css/index.css">
<link rel="stylesheet" href="/styles/components/highlight/highlight.css">

  
</head>
  <body>
    <header class="site-header">
  <div class="site-header-brand">
    
      <span class="site-header-brand-title">
        <a href="/">wu24</a>
      </span>
    
    
      <span class="site-header-brand-motto"> | 一直很安静</span>
    
  </div>
  <div class="site-header-right">
    <nav class="site-header-navigation">
      
        <a href="/" target="_self">首页</a>
      
        <a href="/archives/" target="_self">归档</a>
      
        <a href="/tags/" target="_self">标签</a>
      
        <a href="/categories/" target="_self">分类</a>
      
        <a href="/about/" target="_self">关于</a>
      
    </nav>
    <div class="site-header-btn">
      
        <a href="https://github.com/dongyuanxin/" target="_blank" id="site-github">
          <i class="fa fa-github-alt"></i>
        </a>
      
      <a href="javascript:void(0);" id="site-search">
        <i class="fa fa-search"></i>
      </a>
      <a href="javascript:void(0);" id="site-nav-btn">
        <i class="fa fa-ellipsis-v"></i>
      </a>
    </div>
  </div>
</header>
<nav class="table-content" id="site-nav">
  <div class="table-content-title">
    <span>导航</span>
  </div>
  <div class="table-content-main">
    <ol class="toc">
      
        <li class="toc-item">
          <a href="/" target="_self">
            首页
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/archives/" target="_self">
            归档
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/tags/" target="_self">
            标签
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/categories/" target="_self">
            分类
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/about/" target="_self">
            关于
          </a>
        </li>
      
    </ol>
  </div>
</nav>
<div id="site-process"></div>
    <main>
      
  <div class="passage">
  <div class="passage-meta">
    <span>
      <i class="fa fa-calendar"></i>2019-07-07
    </span>
    
      <span>
        | <a href="/categories/c/"><i class="fa fa-bookmark"></i>c++</a>
      </span>
    
    
      <span>
        | <i class="fa fa-unlock-alt"></i>UNLOCK
      </span>
    
  </div>
  <h1 class="passage-title">
    位运算总结
  </h1>
  
  <article class="passage-article">
    <h4 id="一-前言"><a href="#一-前言" class="headerlink" title="一.前言"></a>一.前言</h4><p>今天刷leetcode碰到与位运算相关的题目，平时编程不经常使用位运算符，因此对位运算符的理解不够深入，刚好借此机会对位运算符做一个总结。</p>
<h4 id="二-位运算符的使用"><a href="#二-位运算符的使用" class="headerlink" title="二.位运算符的使用"></a>二.位运算符的使用</h4><p>位运算符用来对二进制位进行操作，包括：按位与（&amp;）、按位或（|）、按位异或（^）、按位取反（~）、按位左移（&lt;&lt;）、按位右移（&gt;&gt;）。</p>
<h5 id="1-按位与-amp"><a href="#1-按位与-amp" class="headerlink" title="1. 按位与(&amp;)"></a>1. 按位与(&amp;)</h5><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">   <span class="keyword">int</span> a=<span class="number">10</span>;</span><br><span class="line">   <span class="keyword">int</span> b=<span class="number">-14</span>;</span><br><span class="line">   <span class="keyword">int</span> c=a&amp;b;</span><br><span class="line">   <span class="built_in">cout</span>&lt;&lt;c;       <span class="comment">//输出 2</span></span><br><span class="line">   <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h6 id="a-amp-b计算过程"><a href="#a-amp-b计算过程" class="headerlink" title="a&amp;b计算过程"></a>a&amp;b计算过程</h6><ul>
<li>10的原码为:  0000 0000 0000 0000 0000 0000 0000 1010</li>
<li>10的补码为:  0000 0000 0000 0000 0000 0000 0000 1010</li>
<li>-14的原码为: 1000 0000 0000 0000 0000 0000 0000 1110</li>
<li>-14的补码为: 1111 1111 1111 1111 1111 1111 1111 0010</li>
<li>将10的补码与-14的补码按位与:</li>
<li>0000 0000 0000 0000 0000 0000 0000 1010   (10的补码)</li>
<li>1111 1111 1111 1111 1111 1111 1111 0010   (-14的补码)</li>
<li>0000 0000 0000 0000 0000 0000 0000 0010   (按位与的结果)</li>
<li>将按位与的结果转换为原码：0000 0000 0000 0000 0000 0000 0000 0010</li>
<li>最终得到结果2<h5 id="2-按位或"><a href="#2-按位或" class="headerlink" title="2. 按位或(|)"></a>2. 按位或(|)</h5><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">   <span class="keyword">int</span> a=<span class="number">10</span>;</span><br><span class="line">   <span class="keyword">int</span> b=<span class="number">-14</span>;</span><br><span class="line">   <span class="keyword">int</span> c=a|b;</span><br><span class="line">   <span class="built_in">cout</span>&lt;&lt;c;       <span class="comment">//输出 -6</span></span><br><span class="line">   <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h6 id="a-b计算过程"><a href="#a-b计算过程" class="headerlink" title="a|b计算过程"></a>a|b计算过程</h6><ul>
<li>10的原码为:  0000 0000 0000 0000 0000 0000 0000 1010</li>
<li>10的补码为:  0000 0000 0000 0000 0000 0000 0000 1010</li>
<li>-14的原码为: 1000 0000 0000 0000 0000 0000 0000 1110</li>
<li>-14的补码为: 1111 1111 1111 1111 1111 1111 1111 0010</li>
<li>将10的补码与-14的补码按位或:</li>
<li>0000 0000 0000 0000 0000 0000 0000 1010   (10的补码)</li>
<li>1111 1111 1111 1111 1111 1111 1111 0010   (-14的补码)</li>
<li>1111 1111 1111 1111 1111 1111 1111 1010   (按位与的结果)</li>
<li>将按位与的结果转换为原码：1000 0000 0000 0000 0000 0000 0000 0110</li>
<li>最终得到结果-6<h6 id="3-按位异或"><a href="#3-按位异或" class="headerlink" title="3. 按位异或(^)"></a>3. 按位异或(^)</h6><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">   <span class="keyword">int</span> a=<span class="number">10</span>;</span><br><span class="line">   <span class="keyword">int</span> b=<span class="number">-14</span>;</span><br><span class="line">   <span class="keyword">int</span> c=a^b;</span><br><span class="line">   <span class="built_in">cout</span>&lt;&lt;c;       <span class="comment">//输出 -8</span></span><br><span class="line">   <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h6 id="a-b计算过程-1"><a href="#a-b计算过程-1" class="headerlink" title="a^b计算过程"></a>a^b计算过程</h6><ul>
<li>10的原码为:  0000 0000 0000 0000 0000 0000 0000 1010</li>
<li>10的补码为:  0000 0000 0000 0000 0000 0000 0000 1010</li>
<li>-14的原码为: 1000 0000 0000 0000 0000 0000 0000 1110</li>
<li>-14的补码为: 1111 1111 1111 1111 1111 1111 1111 0010</li>
<li>将10的补码与-14的补码按位异或:</li>
<li>0000 0000 0000 0000 0000 0000 0000 1010   (10的补码)</li>
<li>1111 1111 1111 1111 1111 1111 1111 0010   (-14的补码)</li>
<li>1111 1111 1111 1111 1111 1111 1111 1000   (按位异或的结果)</li>
<li>将按位异或的结果转换为原码：1000 0000 0000 0000 0000 0000 0000 1000</li>
<li>最终得到结果-8<h5 id="4-按位取反"><a href="#4-按位取反" class="headerlink" title="4. 按位取反(~)"></a>4. 按位取反(~)</h5><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">   <span class="built_in">cout</span>&lt;&lt;~<span class="number">10</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">   <span class="built_in">cout</span>&lt;&lt;~<span class="number">-10</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">   <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h6 id="10的计算过程"><a href="#10的计算过程" class="headerlink" title="~10的计算过程"></a>~10的计算过程</h6><ul>
<li>10的原码为:      0000 0000 0000 0000 0000 0000 0000 1010</li>
<li>10的补码为:      0000 0000 0000 0000 0000 0000 0000 1010</li>
<li>10的补码取反:    1111 1111 1111 1111 1111 1111 1111 0101</li>
<li>取反结果转为原码：1000 0000 0000 0000 0000 0000 0000 1011</li>
<li>最终得到结果-11<h6 id="10的计算过程-1"><a href="#10的计算过程-1" class="headerlink" title="~-10的计算过程"></a>~-10的计算过程</h6></li>
<li>-10的原码为:         1000 0000 0000 0000 0000 0000 0000 1010</li>
<li>-10的补码为:         1111 1111 1111 1111 1111 1111 1111 0110</li>
<li>-10的补码按位取反:    0000 0000 0000 0000 0000 0000 0000 1001</li>
<li>取反结果转为原码：    0000 0000 0000 0000 0000 0000 0000 1001</li>
<li>最终得到结果9<h5 id="5-按位右移（-gt-gt-）"><a href="#5-按位右移（-gt-gt-）" class="headerlink" title="5.按位右移（&gt;&gt;）"></a>5.按位右移（&gt;&gt;）</h5><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">   <span class="keyword">int</span> a=<span class="number">10</span>;</span><br><span class="line">   <span class="keyword">int</span> b=<span class="number">-10</span>;</span><br><span class="line">   <span class="keyword">unsigned</span> <span class="keyword">int</span> c=<span class="number">10</span>;</span><br><span class="line">   <span class="built_in">cout</span>&lt;&lt;(a&gt;&gt;<span class="number">2</span>)&lt;&lt;<span class="built_in">endl</span>; #输出 <span class="number">2</span></span><br><span class="line">   <span class="built_in">cout</span>&lt;&lt;(b&gt;&gt;<span class="number">2</span>)&lt;&lt;<span class="built_in">endl</span>; #输出 <span class="number">-3</span></span><br><span class="line">   <span class="built_in">cout</span>&lt;&lt;(c&gt;&gt;<span class="number">2</span>)&lt;&lt;<span class="built_in">endl</span>; #输出 <span class="number">2</span></span><br><span class="line">   </span><br><span class="line">   <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h6 id="规则："><a href="#规则：" class="headerlink" title="规则："></a>规则：</h6><ul>
<li>有符号数：按二进制形式把所有数字向右移动相应的位数，低位移出（舍弃）。如果右移正数，高位空位补0。如果右移负数，高位空位补1.</li>
<li>无符号数：按二进制形式把所有数字向右移动相应的位数，低位移出（舍弃），高位的空位补0。相当于除以2的n次方<h6 id="对于有符号正数a"><a href="#对于有符号正数a" class="headerlink" title="对于有符号正数a"></a>对于有符号正数a</h6></li>
<li>10的原码为:      0000 0000 0000 0000 0000 0000 0000 1010</li>
<li>10的补码为:      0000 0000 0000 0000 0000 0000 0000 1010</li>
<li>10的补码右移2位: 0000 0000 0000 0000 0000 0000 0000 0010  </li>
<li>右移结果转为原码:0000 0000 0000 0000 0000 0000 0000 0010</li>
<li>最终得到结果2<h6 id="对于有符号正数b"><a href="#对于有符号正数b" class="headerlink" title="对于有符号正数b"></a>对于有符号正数b</h6></li>
<li>-10的原码为:      1000 0000 0000 0000 0000 0000 0000 1010</li>
<li>-10的补码为:      1111 1111 1111 1111 1111 1111 1111 0110</li>
<li>-10的补码右移两位: 1111 1111 1111 1111 1111 1111 1111 1101</li>
<li>右移结果转为原码： 1000 0000 0000 0000 0000 0000 0000 0011</li>
<li>最终得到结果-3<h6 id="对于无符号数c"><a href="#对于无符号数c" class="headerlink" title="对于无符号数c"></a>对于无符号数c</h6></li>
<li>10的原码为:      0000 0000 0000 0000 0000 0000 0000 1010</li>
<li>10的补码为:      0000 0000 0000 0000 0000 0000 0000 1010</li>
<li>10的补码右移2位: 0000 0000 0000 0000 0000 0000 0000 0010  </li>
<li>右移结果转为原码:0000 0000 0000 0000 0000 0000 0000 0010</li>
<li>最终得到结果2<h5 id="5-按位左移（-lt-lt-）"><a href="#5-按位左移（-lt-lt-）" class="headerlink" title="5.按位左移（&lt;&lt;）"></a>5.按位左移（&lt;&lt;）</h5><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">   <span class="keyword">int</span> a=<span class="number">10</span>;</span><br><span class="line">   <span class="keyword">int</span> b=<span class="number">-10</span>;</span><br><span class="line">   <span class="built_in">cout</span>&lt;&lt;(a&lt;&lt;<span class="number">2</span>)&lt;&lt;<span class="built_in">endl</span>; #输出 <span class="number">40</span></span><br><span class="line">   <span class="built_in">cout</span>&lt;&lt;(b&lt;&lt;<span class="number">28</span>)&lt;&lt;<span class="built_in">endl</span>; #输出 <span class="number">1610612736</span></span><br><span class="line">   </span><br><span class="line">   <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h6 id="规则：-1"><a href="#规则：-1" class="headerlink" title="规则："></a>规则：</h6><p>*对于有符号数和无符号数：按二进制形式把所有数字向左移动相应的位数，高位移出（舍弃），低位的空位补0。相当于乘以2的n次方</p>
<h6 id="对于有符号正数a-1"><a href="#对于有符号正数a-1" class="headerlink" title="对于有符号正数a"></a>对于有符号正数a</h6><ul>
<li>10的原码为:      0000 0000 0000 0000 0000 0000 0000 1010</li>
<li>10的补码为:      0000 0000 0000 0000 0000 0000 0000 1010</li>
<li>10的补码左移2位: 0000 0000 0000 0000 0000 0000 0010 1000  </li>
<li>左移结果转为原码:0000 0000 0000 0000 0000 0000 0010 1000</li>
<li>最终得到结果40<h6 id="对于有符号正数b-1"><a href="#对于有符号正数b-1" class="headerlink" title="对于有符号正数b"></a>对于有符号正数b</h6></li>
<li>-10的原码为:      1000 0000 0000 0000 0000 0000 0000 1010</li>
<li>-10的补码为:      1111 1111 1111 1111 1111 1111 1111 0110</li>
<li>-10的补码左移28位: 0110 0000 0000 0000 0000 0000 0000 0000</li>
<li>右移结果转为原码： 0110 0000 0000 0000 0000 0000 0000 0000</li>
<li>最终得到结果 2^30+2^29=1610612736</li>
</ul>

  </article>
  <aside class="table-content" id="site-toc">
  <div class="table-content-title">
    <i class="fa fa-arrow-right fa-lg" id="site-toc-hide-btn"></i>
    <span>目录</span>
  </div>
  <div class="table-content-main">
    <ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#一-前言"><span class="toc-text">一.前言</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#二-位运算符的使用"><span class="toc-text">二.位运算符的使用</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1-按位与-amp"><span class="toc-text">1. 按位与(&amp;)</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#a-amp-b计算过程"><span class="toc-text">a&amp;b计算过程</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2-按位或"><span class="toc-text">2. 按位或(|)</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#a-b计算过程"><span class="toc-text">a|b计算过程</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#3-按位异或"><span class="toc-text">3. 按位异或(^)</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#a-b计算过程-1"><span class="toc-text">a^b计算过程</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#4-按位取反"><span class="toc-text">4. 按位取反(~)</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#10的计算过程"><span class="toc-text">~10的计算过程</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#10的计算过程-1"><span class="toc-text">~-10的计算过程</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#5-按位右移（-gt-gt-）"><span class="toc-text">5.按位右移（&gt;&gt;）</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#规则："><span class="toc-text">规则：</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#对于有符号正数a"><span class="toc-text">对于有符号正数a</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#对于有符号正数b"><span class="toc-text">对于有符号正数b</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#对于无符号数c"><span class="toc-text">对于无符号数c</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#5-按位左移（-lt-lt-）"><span class="toc-text">5.按位左移（&lt;&lt;）</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#规则：-1"><span class="toc-text">规则：</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#对于有符号正数a-1"><span class="toc-text">对于有符号正数a</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#对于有符号正数b-1"><span class="toc-text">对于有符号正数b</span></a></li></ol></li></ol></li></ol>
  </div>
</aside>
  
    <aside class="passage-copyright">
      <div>本文作者: wu24</div>
      
        <div>
          原文链接: 
          <a href target="_blank">https://wu24.gitee.io/passages/2019-7-7-c++位运算总结/</a>
        </div>
      
      <div>
        版权声明: 本博客所有文章除特别声明外, 均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> 许可协议. 转载请注明出处!
      </div>
    </aside>
  
  
    <div class="passage-tags">
     
      <a href="/tags/c/"><i class="fa fa-tags"></i>c++</a>
    
    </div>
  
</div>

    </main>
    
      
<div class="site-comment-contanier" data-plateform="leancloud">
  
    <p id="site-comment-info">
      <i class="fa fa-spinner fa-spin"></i> 评论加载中
    </p>
    <div id="site-comment"></div>
  
</div>
    
    <div class="site-footer-wrapper">
  <footer class="site-footer">
    
    <div class="site-footer-info">
      <i class="fa fa-clock-o"></i> 本站已稳定运行<span id="site-time"></span>
    </div>
    
      <div class="site-footer-info">
        <i class="fa fa-paw"></i> 您是本站第 <span id="site-count"></span> 位访客
      </div>
    
    
      <div class="site-footer-info">
        <i class="fa fa-at"></i> Email: 204651470@qq.com
      </div>
    
    <div class="site-footer-info">
      <i class="fa fa-copyright"></i> 
      2019 <a href="https://github.com/dongyuanxin/theme-ad/" target="_blank">Theme-AD</a>.
      Created by <a href="https://godbmw.com/" target="_blank">GodBMW</a>.
      All rights reserved.
    </div>
  </footer>
</div>
    <div id="site-layer" style="display:none;">
  <div class="site-layer-content">
    <div class="site-layer-header">
      <span class="site-layer-header-title" id="site-layer-title"></span>
      <i class="fa fa-close" id="site-layer-close"></i>
    </div>
    <div class="site-layer-body" id="site-layer-container">
      <div class="site-layer-input" id="site-layer-search" style="display: none;">
        <div class="site-layer-input-choose">
          <a href="javascript:void(0);" title="Change Search Engine">Google</a>
        </div>
        <input type="text">
        <i class="fa fa-search"></i>
      </div>
      
      <div id="site-layer-welcome" style="display:none;"></div>
    </div>
  </div>
</div>
    

<div class="bottom-bar">
  <div class="bottom-bar-left">
    <a href="/passages/2019-7-21-Robots协议 /" data-enable="true">
      <i class="fa fa-arrow-left"></i>
    </a>
    <a href="/passages/2019-7-7-java位运算总结/" data-enable="true">
      <i class="fa fa-arrow-right"></i>
    </a>
  </div>
  <div class="bottom-bar-right">
    <a href="javascript:void(0);" data-enable="true" id="site-toc-show-btn">
      <i class="fa fa-bars"></i>
    </a>
    
      <a href="#site-comment" data-enable="true">
        <i class="fa fa-commenting"></i>
      </a>
    
    <a href="javascript:void(0);" id="site-toggle-share-btn">
      <i class="fa fa-share-alt"></i>
    </a>
    
    <a href="javascript:void(0);" id="back-top-btn">
      <i class="fa fa-chevron-up"></i>
    </a>
  </div>
</div>
    <div id="share-btn">
  
  
  
  
  
</div>
    
  <script async src="https://www.googletagmanager.com/gtag/js?id="></script>
  <script async>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());

    gtag('config', '');
  </script>



  <script async>
  (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      if (curProtocol === 'https') {
          bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
      }
      else {
          bp.src = 'http://push.zhanzhang.baidu.com/push.js';
      }
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
  })();
  </script>



  <script async>
    (function(){
    var src = (document.location.protocol == "http:") ? "http://js.passport.qihucdn.com/11.0.1.js?":"https://jspassport.ssl.qhimg.com/11.0.1.js?";
    document.write('<script src="' + src + '" id="sozz"><\/script>');
    })();
  </script>


    
  </body>
</html>